const Koa = require("koa2");
const app = new Koa();
const parser = require("koa-parser")
app.use(parser())
const cors = require("koa2-cors")
app.use(cors())
app.keys = ["secret"]
const koaStatic = require('koa-static')
const {upload}= require('./controller/upload/index.js')
const path = require('path');
// const koaBody = require('koa-body')

// 接收post参数解析，写在路由的前面
// app.use(koaBody({
//   multipart: true
// }))

// 配置静态资源加载中间件
app.use(koaStatic(
	path.join('./public/upload') //读取静态文件目录
))

// 填上我们存放图片文件路径
app.use(koaStatic(path.join(__dirname, './public/upload/')))

// 注册路由
const userRouterApi = require("./router/apis/user/user")     // 用户API
// const uploadRouterApi = require("./router/apis/upload/upload")     // 图片上传API
const roleRouterApi = require("./router/apis/user/role")     // 角色API
const ruleRouterApi = require("./router/apis/user/rule")     // 权限API
const catelogueRouterApi = require("./router/apis/catelogue/catelogue")      // 目录API
const chapterRouterApi = require("./router/apis/catelogue/chapter")      // 章节API
const questiontypeApi = require("./router/apis/question/questiontype")       // 题型API
const questionRouterApi = require("./router/apis/question/question")     // 填空题API
const testpaperApi = require("./router/apis/examination/testpaper")      // 试卷API
const achievementApi = require("./router/apis/examination/achievement")      // 试卷API

app.use(userRouterApi.routes())
app.use(roleRouterApi.routes())
app.use(ruleRouterApi.routes())
app.use(catelogueRouterApi.routes())
app.use(chapterRouterApi.routes())
app.use(questiontypeApi.routes())
app.use(testpaperApi.routes())
app.use(achievementApi.routes())
app.use(questionRouterApi.routes())
// app.use(uploadRouterApi.routes())
// app.use(upload()) //  路由


// 端口号
let port = 3000
app.listen(port, () => {
    console.log(`服务器已经启动 端口 ${port}`)
})